#ifndef _JZ_MEMPOOL_H__
#define _JZ_MEMPOOL_H__
#include <assert.h>
#include <string.h>
#include <imp/imp_common.h>
#include <system/imp_alloc.h>

#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern "C"
{
#endif
#endif /* __cplusplus */

typedef struct
{
	char method[MAX_NAME_LEN];
	void*   (*init)(void *base, int size, char *handlerName);
	void* (*memalloc)(void*handler, int size, char *memName);
	void  (*memfree)(void *handler, void *ptr);
	void  (*dump)(void *handler);
	void  (*dump_to_file)(void *handler);
} PoolMemAlloc;

typedef struct PoolAllocInfo{
	struct PoolAllocInfo *n_info;
	char owner[MAX_NAME_LEN];
	uint32_t vaddr;
	uint32_t paddr;
	int length;
	int ref_cnt;
	IMPMemAttr mem_attr;
} PoolAllocInfo;

typedef enum {
	ALLOC_NOT_INITIALIZED,
	ALLOC_ALREADY_INITIALIZED,
} PoolAllocInitStatus;

typedef struct {
	char method[MAX_NAME_LEN];
	uint32_t vaddr;
	uint32_t paddr;
	int length;
	uint32_t (*get_paddr)(uint32_t vaddr);
	uint32_t (*get_vaddr)(uint32_t paddr);
	int (*flush_cache)(uint32_t vaddr, size_t size, uint32_t dir);
} MemAlloc2;

struct MEMPoolAlloc;
typedef struct  MEMPoolAlloc MEMPoolAlloc;

struct MEMPoolAlloc {
	struct PoolAllocInfo info;
	PoolAllocInitStatus init_status;
	MemAlloc2 mem_alloc;
	PoolMemAlloc mem_manager;
	void* (*alloc_mem)(MEMPoolAlloc *alloc, int size, char *owner);
	void* (*sp_alloc_mem)(MEMPoolAlloc *alloc, void *ptr);
	void  (*free_mem)(MEMPoolAlloc *alloc, void *ptr);
	struct PoolAllocInfo* (*getAllocInfo)(MEMPoolAlloc *alloc, void *ptr);
	IMPMemAttr (*get_mem_attr)(MEMPoolAlloc *alloc, void *ptr);
	int (*set_mem_attr)(MEMPoolAlloc *alloc, void *ptr, IMPMemAttr attr);
	int (*dump_mem_status)(MEMPoolAlloc *alloc);
	int (*dump_mem_to_file)(MEMPoolAlloc *alloc);
};

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

#endif
